﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Data.Linq;
using System.Linq;
using WX.WMS.BLL;
using WX.WMS.Common;
using WX.WMS.DataModel;


public partial class Index : PageBase
{
    protected enum TitleEuem
    { 
        gkxx=0,//公开信息
        xtsz=1,//系统设置
        cgkd=2,//采购开单
        xskd=3,//销售开单
        kckd=4,//库存开单
        gllc=5//管理流程
    }
    private int count = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Databang();
        }
    }
    /// <summary>
    /// 根据权限初始化用户菜单
    /// </summary>
    protected void Databang()
    {

        AuthorityBLL Authority = new AuthorityBLL();
        var RL = Authority.GetRoleAuthorityList();


        

        DataTable table = new DataTable();
        table.Columns.Add("ID");
        table.Columns.Add("Title");
        table.Columns.Add("Type");

        int id = 0;
        DataRow row;



        if (RL.Where(t=>t.T_Authority.TypeID==(int)TitleEuem.cgkd).Count()>0)
        {
            row = table.NewRow();
            row["Type"] = (int)TitleEuem.cgkd;
            row["Title"] = "采购开单";
            row["ID"] = id;
            id++;
            table.Rows.Add(row);
        }

        if (RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.xskd).Count() > 0)
        {
            row = table.NewRow();
            row["Type"] = (int)TitleEuem.xskd;
            row["Title"] = "销售开单";
            row["ID"] = id;
            id++;
            table.Rows.Add(row);
        }

        if (RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.kckd).Count() > 0)
        {
            row = table.NewRow();
            row["Type"] = (int)TitleEuem.kckd;
            row["Title"] = "库存开单";
            row["ID"] = id;
            id++;
            table.Rows.Add(row);
        }

        if (RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.gllc).Count() > 0)
        {
            row = table.NewRow();
            row["Type"] = (int)TitleEuem.gllc;
            row["Title"] = "管理流程";
            row["ID"] = id;
            table.Rows.Add(row);
            id++;
        }

        if (RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.xtsz).Count() > 0)
        {
            row = table.NewRow();
            row["Type"] = (int)TitleEuem.xtsz;
            row["Title"] = "系统设置";
            row["ID"] = id;
            id++;
            table.Rows.Add(row);
        }

        count = id;
        TitleRepeater.DataSource = table;
        TitleRepeater.DataBind();
    }
    protected void TitleRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Repeater ItemRepeater = (Repeater)e.Item.FindControl("ItemRepeater");

        DataRowView rowv = (DataRowView)e.Item.DataItem;


        AuthorityBLL Authority = new AuthorityBLL();
        var RL = Authority.GetRoleAuthorityList();

        int type = Convert.ToInt32(rowv["Type"]);
        switch (type)
        {
            //case (int)TitleEuem.gkxx:///公开信息 -1
            //    DataTable talbe = new DataTable();
            //    talbe.Columns.Add("WebUrl");
            //    talbe.Columns.Add("AuthorityName");

            //    DataRow row = talbe.NewRow();
            //    row["WebUrl"] = "Products/NewsProducts.aspx";
            //    row["AuthorityName"] = "最新商品";
            //    talbe.Rows.Add(row);

            //    row = talbe.NewRow();
            //    row["WebUrl"] = "Products/ShowProductsList.aspx";
            //    row["AuthorityName"] = "物品搜索";
            //    talbe.Rows.Add(row);

            //    ItemRepeater.DataSource = talbe;
            //    ItemRepeater.DataBind();  ///
            //    break;
            case (int)TitleEuem.xtsz:///系统设置0
                ItemRepeater.DataSource = RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.xtsz && t.RoleID == UserInfo.ROLE_ID).OrderBy(t => t.T_Authority.AuthorityName);
                ItemRepeater.DataBind();
                break;
            case (int)TitleEuem.cgkd:///采购开单1
                ItemRepeater.DataSource = RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.cgkd && t.RoleID == UserInfo.ROLE_ID).OrderBy(t => t.T_Authority.AuthorityName);
                ItemRepeater.DataBind();  ///
                break;
            case (int)TitleEuem.xskd:///销售开单2
                ItemRepeater.DataSource = RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.xskd && t.RoleID == UserInfo.ROLE_ID).OrderBy(t => t.T_Authority.AuthorityName);
                ItemRepeater.DataBind();  ///
                break;
            case (int)TitleEuem.kckd:///库存开单3
                ItemRepeater.DataSource = RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.kckd && t.RoleID == UserInfo.ROLE_ID).OrderBy(t => t.T_Authority.AuthorityName);
                ItemRepeater.DataBind();  ///
                break;
            case (int)TitleEuem.gllc:///管理流程4
                ItemRepeater.DataSource = RL.Where(t => t.T_Authority.TypeID == (int)TitleEuem.gllc && t.RoleID == UserInfo.ROLE_ID).OrderBy(t => t.T_Authority.AuthorityName);
                ItemRepeater.DataBind();  ///
                break;
        }
    }
    protected int GetCount()
    {
        return count;
    }
}
